﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/_LayoutChat.cshtml";
}
<script type="text/javascript">
    socket.on('updateusers', function (data) {        
        $('#users').empty(); 
        var html = "";//lay danh sach user online
        $.each(data, function (key, value){
            html = "";
            html += "<b class=\"first\" style=\"position:relative;left:5px;background:#40C012;border-radius:12.5px;display:block;float:left;height:12.5px;width:12.5px;top:2px;\">";
            html += "</b>";
            $('#users').append('<div><b>' + html + '</b></div>');
            if (key === objCurrent.username) {
                html = "";
                html += "<b class=\"first\" style=\"color:#1C94C4;position:relative;left:10px;\"><a  id=\"current\" style=\"color:#1C94C4;position:relative;left:10px;\">";
                html += key;
                html += "</a></b><br/>";
                $('#users').append('<div><b>' + html + '</b></div>');
            }
            else {
                html = "";
                html += "<b class=\"first\" style=\"color:orange;position:relative;left:10px;\"><a data-toggle=\"modal\" data-target=\"#myModal\" onclick=\"onchat('" + key + "'," + value.userid + ")\" style=\"color:orange;position:relative;left:10px;\" id=\"" + key + "\">";
                html += key;
                html += "</a></b><br/>";
                $('#users').append('<div>' + html + '</div>');
            }            
        });
        
    });

    socket.on('updatechat', function (sname, data) {        
        if (data === null) {
            return;
        }        
        if (data.objName != undefined) {
            if (data.type === true) {
                var _mess_chat = receiveMsg(sname.username, data.obj.msg);
                $("#messages").append(_mess_chat);
            }
            else if (data.type === false) {
                if (sname === objCurrent) {

                }
                else if (data.obj.user_receive.username === objCurrent.username) {
                    var objName = objCurrent.username + "_" + sname.username;
                    createLayoutChat(objName, sname.username);
                    receiveMsgPrivate(sname.username, objName, data.obj.msg);
                }
            }
        }
    });

</script>
<script src="~/Content/md/user/chat.js"></script>
<div class="chat">
	<div  id="cchat" class="main">
		<table class="table table-striped table-bordered bootstrap-datatable datatable"  style="overflow:hidden;">
			<tbody>
				<tr>
					<td style="width:100%;border-right:1px solid red;"  >
						<div id="header_messages" style="display :none;">Private Room</div>
						<div id="messages" style="height:420px;overflow:auto;padding-bottom:25px;">
						</div>
					</td>
				</tr>
                <tr>
                    <td style="width:100%;border-right:1px solid red;">
                        <div class="controls">
								       <textarea id="a-input-chat" style="width:85%" class="input-chat"></textarea>
	                                    <input type="submit" value="Send" style="height:45px;width:10%" id="a-send-chat" class="send-chat">				
							          </div>
                    </td>
                </tr>
			</tbody>
		</table>
	</div>
   
</div>
<table id="tbchats" class="chats" style="width:100%" style="display:none;">
    <tr id="chats">

    </tr>
</table>
<!--
 <ul id="chats" class="chats" style="display:none;">
       
 </ul>
-->